package com.voole.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.voole.dao.BaseDao;
import com.voole.dao.SysActionDao;
import com.voole.dao.SysAuthorityDao;
import com.voole.dao.SysCatalogDao;
import com.voole.dao.SysResourceDao;
import com.voole.entity.SysAuthority;
import com.voole.entity.SysCatalog;
import com.voole.entity.SysResource;
import com.voole.service.ISysAuthorityService;
import com.voole.service.ISysCatalogService;
import com.voole.service.ISysResourceService;

@Service
public class SysResourceServiceImpl implements ISysResourceService {

	@Autowired
	BaseDao baseDao;
	@Autowired
	SysResourceDao sysResourceDao;
	@Autowired
	SysActionDao sysActionDao;
	
	
	/**
	 * 获取所有三级菜单（左侧次级菜单）
	 */
	public List<SysResource> getList() throws Exception {
		return sysResourceDao.getList();
	}
	
	/**
	 * 根据 fatherId（顶侧菜单Id）
	 * 获取所有三级菜单（左侧次级菜单）
	 */
	public List<SysResource> getListByCatalogId(Integer catalogId) throws Exception {
		return sysResourceDao.getListByCatalogId(catalogId);
	}

	/**
	 * 删除三级菜单
	 */
	public Integer delSysResourceAndChild(Integer resourceId) throws Exception {
		Integer delSysResourceNum = sysResourceDao.delSysResource(resourceId);
		Integer delActionNum = sysActionDao.delListByResourceId(resourceId);
		return delSysResourceNum + delActionNum;
	}

	/**
	 * 新增三级菜单
	 * @return id
	 */
	public Integer addResource(String resourceName, Integer catalogId, String url, Integer sort, Integer status) throws Exception {
		SysResource sr = new SysResource();
		sr.setResourcename(resourceName);
		sr.setSort(sort);
		sr.setStatus(status);
		sr.setCatalogid(catalogId);
		sr.setUrl(url);
		sysResourceDao.addSysResource(sr);
		return sr.getId();
	}
	
	
	

}
